package com.ball;

import android.content.Context;
import android.graphics.*;
import android.view.MotionEvent;
import android.view.View;

public class DrawView extends View implements View.OnTouchListener{
	public ColorBall Ball1, Ball2, Ball3;
	private Paint paint;
	private Context myContext;
	public DrawView(Context context) {
		super(context);
		//myContext=context;
		setFocusableInTouchMode(true);
		this.setOnTouchListener(this);
		Ball1 = new ColorBall(context, this, 15, 15, 15);
		Ball2 = new ColorBall(context, this, 80, 80, 5);
	}
	@Override
	protected void onDraw(Canvas canvas) {
		canvas.drawColor(Color.BLUE);
		Ball1.onMove(15, 15, Ball2);
		Ball2.onMove(15, 15, Ball1);
		paint = new Paint();
		paint.setColor(Color.RED);
		paint.setAntiAlias(true);
		Rect r = new Rect((int)(Ball1.getX()-Ball1.getRadius()),(int)(Ball1.getY()-Ball1.getRadius()),(int)(Ball1.getX()+Ball1.getRadius()),(int)(Ball1.getY()+Ball1.getRadius()));
		canvas.drawRect(r, paint);
		//canvas.drawCircle(Ball1.getX(), Ball1.getY(), Ball1.getRadius(), paint);
		canvas.drawCircle((float)Ball2.getX(), (float)Ball2.getY(), (float)Ball2.getRadius(), paint);
		invalidate();
	}
	public boolean onTouch(View v, MotionEvent event) {
		Ball1.setX(event.getX());
		Ball1.setY(event.getY());
		invalidate();
		return true;
	}
}
